<?php

namespace App\Http\Service\member;

class MemberService {

    public function signIn($request) {
        if (!$token = auth('api')->attempt($request->post())) {
            return false;
        }
        $userDataObject = $this->respondWithToken($token);
        $userData = [
            'accessToken' => $userDataObject->original['access_token'],
            'tokenType' => $userDataObject->original['token_type'],
            'expiresIn' => $userDataObject->original['expires_in']
        ];
        return $userData;
    }

    /**
     * 用户详情
     * 
     */
    public function userInfo() {
        return auth('api')->user();
    }

    public function logOut() {
        return auth('api')->logout();
    }

    /**
     * 刷新token
     * 
     */
    protected function respondWithToken($token) {
        return response()->json(
                        [
                            'access_token' => $token,
                            'token_type' => 'bearer',
                            'expires_in' => auth('api')->factory()->getTTL() * 60
                        ]
        );
    }

}
